﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.MVC;
using Billing.Models;
using Billing.IService.Entry;

namespace Billing.Controllers
{
    public class BillingController : AsyncControllerBase
    {
        #region Modify

        public void ModifyAsync(string user,string resource,string code,decimal? amount,bool mode) {
            ModifyBillingModel model = new ModifyBillingModel {
                BillingCode=user,
                BillingSource=resource,
                Source=code,
                Address = Request.UserHostAddress,
                Amount = amount == null ? decimal.Zero : amount.Value,
                Mode = mode,
                ConfigName = "filter:ip:billing:modify"
            };
            this.InitModel(model);
        }

        public ActionResult ModifyCompleted(bool result)
        {
            return Content(result.ToString());
        }

        #endregion Modify

        #region Get

        public void GetAsync(string user, string resource)
        {
            GetBillingModel model = new GetBillingModel
            {
                BillingCode = user,
                BillingSource = resource,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:billing:get"
            };
            this.InitModel(model);
        }

        public ActionResult GetCompleted(BillingEntry entry)
        {
            if (entry==null)
                return new EmptyResult();
            return Json(entry);
        }

        #endregion Get

    }
}
